package com.lwj.controller.system;

import com.lwj.dto.system.MenuDto;
import com.lwj.entity.RestEntity;
import com.lwj.service.system.MenuService;
import com.lwj.vo.system.MenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags ="菜单接口")
@RestController()
@RequestMapping("/api/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @ApiOperation(value = "菜单树")
    @GetMapping("/tree")
    public RestEntity<List<MenuVo>> menuTree(@RequestParam(value = "type",defaultValue = "") String type){
        return RestEntity.success(menuService.menuTree(type));
    }


    @ApiOperation(value = "保存菜单")
    @PostMapping("/save")
    public RestEntity<String> updateMenu(@RequestBody @Valid MenuDto menuDto){
        return RestEntity.success(menuService.save(menuDto));
    }

    @ApiOperation(value = "用户菜单")
    @GetMapping("/userMenu")
    public RestEntity<List<MenuVo>> userMenu(@RequestParam(value = "departmentRoleId",required = false) String departmentRoleId){
        return RestEntity.success(menuService.userMenu(departmentRoleId));
    }

    @ApiOperation(value = "修改菜单状态")
    @PostMapping("/changeStatus")
    public RestEntity<String> changeStatus(@RequestBody  MenuDto menuDto){
        menuService.changeStatus(menuDto);
        return RestEntity.success();
    }


}
